import { View } from "../../mvc/core/View";
import { ILayer } from "../../mvc/interfaces/ILayer";
import { ILayOut } from "../../../modules/interfaces/ILayOut";
import { LayerManager } from "./LayerManager";
import { Global } from "../../../com/gengine/global/Global";
import { HintBtnView } from "../view/mapUI/HintBtnView";
import { _firLineNum } from "../../../this/_firLineNum";
import { Vector } from "../../../__AS3__/vec/Vector";
type int = number;
//class RightTopUILayer
    
    export  class RightTopUILayer extends View implements ILayer, ILayOut
    {
        constructor()
        {
            super();
            this.vcDisplaObject = new Vector.<flash.display.DisplayObject>();
            this.dicDisplayObjectIndex = new Map<any, any> /* flash.utils.Dictionary */();
            this.dicDisplayObjectIndex2 = new Map<any, any> /* flash.utils.Dictionary */();
            tabChildren = false;
            mouseEnabled = false;
            layer = LayerManager.uiLayer;
            this.createChildren();
            this.resetPosition();
            return;
        }

        /* internal  */createChildren(): void
        {
            this._iconContainer = new Object /* flash.display.Sprite */();
            this._iconContainer.mouseEnabled = false;
            this.addChild(this._iconContainer);
            return;
        }

        /* internal  */resetChildPosition(): void
        {
            var loc2=0;
            var loc3=0;
            var loc5=0;
            var loc6=0;
            var loc1=this.sortEveryLine(this.vcDisplaObject);
            var loc4;
            if ((loc4 = loc1[0] as Array<any>) && loc4.length > this._firLineNum) 
            {
                loc1[0] = [];
                loc5 = 0;
                loc2 = 0;
                while (loc2 < loc4.length) 
                {
                    loc6 = loc5 != 0 ? this._otherLineNum : _firLineNum;
                    if ((loc1[loc5] as Array<any>).length < loc6) 
                    {
                        (loc1[loc5] as Array<any>).push(loc4[loc2]);
                    }
                    else 
                    {
                        if ((loc5 = loc5 + 1) == loc1.length) 
                        {
                            loc1.push([]);
                        }
                        (loc1[loc5] as Array<any>).push(loc4[loc2]);
                    }
                    ++loc2;
                }
            }
            loc3 = 0;
            while (loc3 < loc1.length) 
            {
                loc2 = 0;
                while (loc2 < (loc1[loc3] as Array<any>).length) 
                {
                    loc1[loc3][loc2].x = -(loc2 + 1) * this.HorizenGap;
                    loc1[loc3][loc2].y = loc3 * 67;
                    ++loc2;
                }
                ++loc3;
            }
            this._iconContainer.x = Global.stage.stageWidth - 170;
            return;
        }

        /* internal  */sortEveryLine(arg1: Vector.<flash.display.DisplayObject>): Array<any>
        {
            var loc2=0;
            var loc3=null;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            var loc7=null;
            var loc8=null;
            var loc1=new Map<any, any> /* flash.utils.Dictionary */();
            var loc9=0;
            var loc10=arg1;
            for(loc3 of loc10) 
            {
                if (loc3 is HintBtnView && (loc3 as HintBtnView).line > 0) 
                {
                    loc2 = (loc3 as HintBtnView).line;
                }
                else 
                {
                    loc2 = 0;
                }
                if (loc1[loc2] == null) 
                {
                    loc1[loc2] = [];
                }
                (loc1[loc2] as Array<any>).push(loc3);
            }
            loc4 = [];
            loc9 = 0;
            loc10 = loc1;
            for (loc5 in loc10) 
            {
                loc4.push({"line": parseInt(loc5), "arr": loc1[loc5]});
            }
            loc4.sortOn("line", Array.NUMERIC);
            loc7 = [];
            loc9 = 0;
            loc10 = loc4;
            for(loc8 of loc10) 
            {
                (loc6 = loc8["arr"] as Array<any>).sort(this.sortDisplayPosition);
                loc7.push(loc6);
            }
            return loc7;
        }

        /* internal  */sortDisplayPosition(arg1: Object /* flash.display.DisplayObject */, arg2: Object /* flash.display.DisplayObject */): int
        {
            var loc1=int.MAX_VALUE;
            var loc2=int.MAX_VALUE;
            if (typeof arg1 === "hintbtnview") 
            {
                loc1 = (arg1 as HintBtnView).index;
            }
            if (typeof arg2 === "hintbtnview") 
            {
                loc2 = (arg2 as HintBtnView).index;
            }
            if (loc2 < loc1) 
            {
                return 1;
            }
            if (loc2 == loc1) 
            {
                return 0;
            }
            return -1;
        }

        public addPopUp(arg1: Object /* flash.display.DisplayObject */, arg2: Boolean=false): void
        {
            if (arg1 && this.contains(arg1) == false) 
            {
                this._iconContainer.addChild(arg1);
                this.vcDisplaObject.push(arg1);
                this.resetChildPosition();
            }
            return;
        }

        public centerPopup(arg1: Object /* flash.display.DisplayObject */): void
        {
            return;
        }

        public setPosition(arg1: Object /* flash.display.DisplayObject */, arg2: int, arg3: int): void
        {
            return;
        }

        public isTop(arg1: Object /* flash.display.DisplayObject */): Boolean
        {
            if (this._iconContainer.contains(arg1)) 
            {
                return this._iconContainer.getChildIndex(arg1) == (this._iconContainer.numChildren - 1);
            }
            return false;
        }

        public removePopup(arg1: Object /* flash.display.DisplayObject */, arg2: Boolean=true): void
        {
            var loc1=0;
            if (this._iconContainer.contains(arg1)) 
            {
                this._iconContainer.removeChild(arg1);
                loc1 = this.vcDisplaObject.indexOf(arg1);
                if (loc1 >= 0) 
                {
                    this.vcDisplaObject.splice(loc1, 1);
                }
                this.resetChildPosition();
            }
            return;
        }

        public isPopup(arg1: Object /* flash.display.DisplayObject */): Boolean
        {
            return this._iconContainer.contains(arg1);
        }

        public setTop(arg1: Object /* flash.display.DisplayObject */): void
        {
            if (this._iconContainer.contains(arg1)) 
            {
                if (this._iconContainer.getChildIndex(arg1) != (this._iconContainer.numChildren - 1)) 
                {
                    this._iconContainer.setChildIndex(arg1, (this._iconContainer.numChildren - 1));
                }
            }
            return;
        }

        public resetPosition(): void
        {
            this.y = 10;
            this._firLineWid = Global.stage.stageWidth - 777;
            this._otherLineWid = Global.stage.stageWidth - 566;
            if (Global.stage.stageWidth != 1000) 
            {
                this._firLineNum = this.eachLineNum(this._firLineWid);
            }
            else 
            {
                this._firLineNum = this.eachLineNum(this._otherLineWid);
            }
            this._otherLineNum = this.eachLineNum(this._otherLineWid);
            this.resetChildPosition();
            return;
        }

        /* internal  */eachLineNum(arg1: int): int
        {
            return Math.floor(arg1 / this.HorizenGap);
        }

        /* internal */ /* const */HorizenGap: int=65;

        /* internal */ /* var */vcDisplaObject: Vector.<flash.display.DisplayObject>;

        /* internal */ /* var */dicDisplayObjectIndex: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */dicDisplayObjectIndex2: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_firLineWid: int;

        /* internal */ /* var */_otherLineWid: int;

        /* internal */ /* var */_firLineNum: int;

        /* internal */ /* var */_otherLineNum: int;

        /* internal */ /* var */_iconContainer: Object /* flash.display.Sprite */;

        public /* var */isTween: Boolean;
    }
